﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DQYT.HTDZ.IDAL;
using Best.Framework.DALFactory;
using DQYT.HTDZ.Model;
using System.Data;

namespace DQYT.HTDZ.BLL
{
    public class BDUserBLL
    {
        private readonly IBDUser dal = DataAccess.CreateBDUser();

        
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(BDUserModel model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BDUserModel model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int ID)
        {
            return dal.Delete(ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            return dal.DeleteList(IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BDUserModel GetModel(int userId)
        {
            return dal.GetModel(userId);
        }

        public BDUserModel GetModel(string userCode)
        {
            return dal.GetModel(userCode);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public BDUserModel GetModelByCache(int ID)
        {
            string CacheKey = "BDUserModel-" + ID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(ID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (BDUserModel)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<BDUserModel> GetModelList(string strWhere)
        {
            return null;
        }

        public DataTable GetBendData(string strWhere)
        {
            return dal.GetBendData(strWhere);
        }

        public bool CheckCode(string USE_CODE)
        {
            return dal.CheckCode(USE_CODE);
        }

        public bool CheckCode(string USE_CODE, string Cur_USE_ID)
        {
            return dal.CheckCode(USE_CODE, Cur_USE_ID);
        }

        public int CheckUserAndPwd(string UserCode, string Pwd)
        {
            return dal.CheckUserAndPwd(UserCode, Pwd);
        }

        public int GetNextID()
        {
            return dal.GetNextID();
        }

        public bool UpdatePwd(int USE_ID, string Pwd)
        {
            return dal.UpdatePwd(USE_ID, Pwd);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        
    }
}
